home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.alaska-software.com
/
2014.06.ftp.alaska-software.com.tar
/
ftp.alaska-software.com
/
3pp
/
mxsetup.old
/
{app}
/
FileDlg.prg
< prev
next >
Wrap
Text File
|
2001-09-14
|
12KB
|
411 lines
**********************************************************************
* FUNCTION MxFileDialog( oWin,;
* cTitle,;
* lOpen,;
* aFilter,;
* cPath,;
* lShowReadonly,;
* lAllowMultiSelect,;
* lPathMustExist,;
* lFileMustExist)
* --> aFileNames
* All Parameters are Optional - if no parameters are entered, a File
* Open Dialog will be initiated in MultiSelect Mode - see below for
* the default Values of the various parameters.
**********************************************************************
* This Program provides a replacement File Open Dialog for the Alaska
* XbpFileDialog() Class which isn't complete in implementation.
* It requires BAP.DLL & BAP.LIB available from the Alaska Web site.
* This code was created by Joe Carrick based on prior code by:
* Ken Levitt based on code from Steffen Rabek and Gernot Trautmann.
* Note that the return Value is an Array of File Names, each of which
* is complete with the full path. The OpenFile routine only returns
* a String which either contains a full file name with path
* -or-
* a String with a Path, followed by File Names separated by chr(0).
* The Array is much easier to extract the File Names from.
* -If lOpen is True and lAllowMultiSelect is True then the Array may
* contain more than one element, depending on how may Files were
* selected.
* -If lOpen is False (Save Dialog) then the Array will contain a max
* of one element.
* -If the Array is empty, then no Files were selected.
**********************************************************************
* NO ACTUAL OPENING OR CLOSING OF FILES IS PROVIDED BY THIS ROUTINE
**********************************************************************
* The DLLFUNCTION calls makes the GetOpenFileNameA system call available
* for later use. The parameter "cStru" is a dummy place holder indicating
* that a character based structure will be passed to GetOpenFileNameA
* when it is used in execution. The name "cStru" is meaningless and
* could be any name. It is just there to indicate that 1 parameter will
* be passed.
**********************************************************************
#include "Dll.ch"
#include "Xbp.ch"
#include "Common.ch"
#pragma Library( "BAP.LIB" )
DLLFUNCTION GetOpenFileNameA( cStru ) USING STDCALL FROM COMDLG32.DLL
DLLFUNCTION GetSaveFileNameA( cStru ) USING STDCALL FROM COMDLG32.DLL
**********************************************************************
* The Following are required to convert from the True/False inputs to
* nFlags for the OpenFile Function Call - Comments eliminated in this
* Listing.
**********************************************************************
#define WORD chr(0)+chr(0)
#define NULL 0
#define OFN_ALLOWMULTISELECT 0x00000200 //512
#define OFN_EXPLORER 0x00080000 //0x80000
#define OFN_FILEMUSTEXIST 0x00001000 //0x1000
#define OFN_HIDEREADONLY 0x00000004 //4
#define OFN_PATHMUSTEXIST 0x00000800 //0x800
#define OFN_READONLY 0x00000001 //1
#define OFN_SHAREAWARE 0x00004000 //0x4000
/*
#define OFN_ALLOWMULTISELECT 512
#define OFN_EXPLORER 0x80000
#define OFN_FILEMUSTEXIST 0x1000
#define OFN_HIDEREADONLY 4
#define OFN_PATHMUSTEXIST 0x800
#define OFN_READONLY 1
#define OFN_SHAREAWARE 0x4000
*/
************************************************************************
* FILE OPEN/SAVE DIALOG
* INPUT Parameters:
* oWin Parent Window Object
* cTitle Title of File Dialog
* lOpen .T. --- Open File Dialog (Default)
* .F. --- Save File Dialog
* aFilter Array of File Types with FilterStrings
* {{ "Program Files (*.PRG)", "*.PRG"},...}
* These items populate the File Types List Box
* cPath Starting drive and path
* lShowReadonlyBox .F.=Default
* lAllowMultiSelect .T.=Default for Open Dialog
* .F.=Always for Save Dialog
* lPathMustExist .T.=Default
* lFileMustExist .F.=Default
* OUTPUT Parameter
* aFileNames Array of File Names Selected including Path
*************************************************************************
FUNCTION MxFileDialog( oWin,;
cTitle,;
lOpen,;
aFilter,;
cPath,;
lShowReadonly,;
lAllowMultiSelect,;
lPathMustExist,;
lFileMustExist)
LOCAL cFile := ""
LOCAL cDir := ""
LOCAL aFileNames := {}
LOCAL i,nFlags := OFN_EXPLORER+OFN_SHAREAWARE
DEFAULT cTitle to "File Dialog"
DEFAULT lOpen to .T.
DEFAULT aFilter to {}
DEFAULT cPath to ""
DEFAULT lShowReadOnly to .F.
DEFAULT lPathMustExist to .T.
DEFAULT lFileMustExist to .F.
if lOpen
DEFAULT lAllowMultiSelect to .T.
else
lAllowMultiSelect := .F.
endif
if lFileMustExist
lPathMustExist := .T.
endif
if lAllowMultiSelect
nFlags := nFlags+OFN_ALLOWMULTISELECT
endif
if !lShowReadOnly
nFlags := nFlags+OFN_HIDEREADONLY
endif
if lPathMustExist
nFlags := nFlags+OFN_PATHMUSTEXIST
endif
if lFileMustExist
nFlags := nFlags+OFN_FILEMUSTEXIST
endif
cFile := OpenFile( oWin, cTitle, lOpen, aFilter, cPath, nFlags )
do while right(cFile,1)==chr(0)
cFile := left(cFile,len(cFile)-1)
enddo
if chr(0)$cFile
cDir := left(cFile,at(chr(0),cFile)-1)+"\"
else
cDir := left(cFile,rat("\",cFile))
endif
cFile := right(cFile,len(cFile)-len(cDir))
do while !empty(cFile)
do while left(cFile,1)==chr(0)
cFile := right(cFile,len(cFile)-1)
enddo
if chr(0)$cFile
i := at(chr(0),cFile)-1
else
i := len(cFile)
endif
aAdd(aFileNames,cDir+left(cFile,i))
cFile := right(cFile,len(cFile)-i)
enddo
RETURN aFileNames
FUNCTION OpenFile( oWin, cTitle, lOpen, aFilter, cPath, nFlags )
*********************************************************
* nFlags = OFN flags added together
*********************************************************
LOCAL hWnd := IIF(oWin=NIL,;
IIf(SetAppWindow()<>Nil,SetAppWindow():getHWND(),AppDeskTop()),;
oWin:getHWND())
LOCAL cLeer := ""
LOCAL cFilter := ""
LOCAL cFileName := replicate(CHR(0), 260) // 260 bytes are required
LOCAL aOFN
LOCAL cOFN
LOCAL nHook := 0
LOCAL i
LOCAL ret := ""
*** Build file extension filtering options ***
IF LEN(aFilter) > 0
FOR i = 1 TO LEN(aFilter)
cFilter += aFilter[i,1]+CHR(0)+aFilter[i,2]+CHR(0)
NEXT
cFilter += CHR(0)
ENDIF
***********************************************************
* Following Code requires the BAP Library
***********************************************************
aOFN = BaInit(20) // BAP.DLL from Gernot Trautmann
BaStruct(aOFN,76) // lStructSize
BaStruct(aOFN,hWnd) // hwndOwner
BaStruct(aOFN,NULL) // hInstance
BaStruct(aOFN,@cFilter) // lpstrFilter
BaStruct(aOFN,NULL) // lpstrCustomFilter
BaStruct(aOFN,0) // nMaxCustFilter
BaStruct(aOFN,1) // nFilterIndex
BaStruct(aOFN,@cFileName) // lpstrFile
BaStruct(aOFN,LEN(cFileName)) // nMaxFile
BaStruct(aOFN,NULL) // lpstrFileTitle
BaStruct(aOFN,0) // nMaxFileTitle
BaStruct(aOFN,@cPath) // lpstrInitialDir
BaStruct(aOFN,@cTitle) // lpstrTitle
BaStruct(aOFN,nflags) // Flags
BaStruct(aOFN,WORD) // nFileOffset
BaStruct(aOFN,WORD) // nFileExtension
BaStruct(aOFN,NULL) // lpstrDefExt
BaStruct(aOFN,NULL) // lCustData
BaStruct(aOFN,nHook) // lpfnHook function link or 0
BaStruct(aOFN,NULL) // lpTemplateName
cOFN = BaAccess(aOFN)
if lOpen
GetOpenFileNameA(cOFN)
else
GetSaveFileNameA(cOFN)
endif
FOR i = 1 TO 8
ret = BaExtract(aOFN)
NEXT
RETURN (IIF(LEFT(ret,1)=CHR(0),"",ret))
PROCEDURE MxFileOpen(aPos,lCenter,aFilter)
LOCAL aFileNames := {}, aSize := setAppWindow():drawingArea:currentSize()
LOCAL cCmdLine := "", cFile
LOCAL oWin, oFiles, oFocus := setAppFocus()
DEFAULT lCenter to .F.
DEFAULT aPos to {1,aSize[2]-300}
DEFAULT aFilter to {}
oFiles := FileDialog():new()
oFiles:fileMustExist := .T.
oFiles:center := lCenter
oFiles:filter := aFilter
oFiles:create(,,aPos)
aFileNames := oFiles:aFileNames
setAppFocus(oFocus)
oFiles:destroy()
if !empty(aFileNames)
if lower(right(alltrim(aFileNames[1]),3))=="exe"
RunShell("",aFileNames[1] )
else
cCmdLine := '/C START "' + aFileNames[1] + '"'
RunShell( cCmdLine )
endif
endif
RETURN
FUNCTION MxGetFileNames(aPos,lCenter,lMultiple, aFilter)
LOCAL aFileNames := {}, aSize := setAppWindow():drawingArea:currentSize()
LOCAL cCmdLine := "", cFile
LOCAL oWin, oFiles, oFocus := setAppFocus()
DEFAULT lCenter to .F.
DEFAULT aPos to {1,aSize[2]-300}
DEFAULT lMultiple to .T.
DEFAULT aFilter to {}
oFiles := FileDialog():new()
oFiles:fileMustExist := .T.
oFiles:center := lCenter
oFiles:allowMultiSelect := lMultiple
oFiles:filter := aFilter
oFiles:create(,,aPos)
aFileNames := oFiles:aFileNames
setAppFocus(oFocus)
oFiles:destroy()
RETURN aFileNames
FUNCTION MxSaveFileName(aPos,lCenter,aFilter)
LOCAL cFileName := "", aSize := setAppWindow():drawingArea:currentSize()
LOCAL cCmdLine := "", cFile
LOCAL oWin, oFiles, oFocus := setAppFocus()
DEFAULT lCenter to .F.
DEFAULT aPos to {1,aSize[2]-300}
DEFAULT aFilter to {}
oFiles := FileDialog():new()
oFiles:fileMustExist := .F.
oFiles:center := lCenter
oFiles:filter := aFilter
oFiles:allowMultiSelect := .F.
oFiles:lOpen := .F.
oFiles:create(,,aPos)
cFileName := iif(!empty(oFiles:aFileNames),oFiles:aFileNames[1],"")
setAppFocus(oFocus)
oFiles:destroy()
RETURN cFileName
CLASS FileDialog from XbpDialog
EXPORTED:
VAR oWin
VAR aFileNames
VAR title
VAR lOpen
VAR filter
VAR startPath
VAR showReadOnlyBox
VAR allowMultiSelect
VAR pathMustExist
VAR fileMustExist
VAR center
METHOD init, create, destroy
ENDCLASS
METHOD FileDialog:init( oParent, oOwner, aPos )
::XbpDialog:init( oParent, oOwner, aPos )
::XbpDialog:visible := .F.
::XbpDialog:sysMenu := .F.
::XbpDialog:titlebar := .F.
::aFileNames := {}
::title := "File Dialog"
::lOpen := .T.
::filter := {{"All Files","*.*"}}
::startPath := ""
::showReadOnlyBox := .F.
::allowMultiSelect := .F.
::pathMustExist := .T.
::fileMustExist := .F.
::center := .F.
RETURN self
METHOD FileDialog:create( oParent, oOwner, aPos )
LOCAL aSize
DEFAULT oParent to AppDeskTop()
DEFAULT oOwner to AppDeskTop()
DEFAULT aPos to {1,aSize[2]-300}
aSize := oOwner:currentSize()
::XbpDialog:create( oParent,;
oOwner,;
IIf(::center,{(aSize[1]-434)/2,(aSize[2]-300)/2},aPos),;
{434,300} )
::aFileNames := MxFileDialog( ::XbpDialog,;
::title,;
::lOpen,;
::filter,;
::startPath,;
::showReadOnlyBox,;
::allowMultiSelect,;
::pathMustExist,;
::fileMustExist)
RETURN self
METHOD FileDialog:destroy()
::XbpDialog:destroy()
RETURN self